﻿var isMoving : boolean;
var targetobject : GameObject;
var waypoints : GameObject[];
var delay : float;
var speed : float;
private var waypointindex : int;
waypointindex = 0;
private var currentTime : float;
currentTime = 0;
  
function Start() {
		// Make the game run as fast as possible in the web player
		Application.targetFrameRate = 60;
}  
  
function Update(){	
	if(isMoving == true){
		targetobject.transform.position = Vector3.MoveTowards(targetobject.transform.position,waypoints[waypointindex].transform.position,speed);
		if(targetobject.transform.position == waypoints[waypointindex].transform.position){
			if(currentTime < delay){
				currentTime += Time.deltaTime;
			}else{
				waypointindex++;
				currentTime = 0;
			}
			
		}
		if(waypointindex >= waypoints.length){
			isMoving = false;
		}	
	}
}
